package com.qyhl.webtv.module_circle.utils.itemview;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qyhl.webtv.basiclib.utils.DateUtils;
import com.qyhl.webtv.basiclib.utils.SpanUtils;
import com.qyhl.webtv.commonlib.entity.circle.CircleHomeBean;
import com.qyhl.webtv.module_circle.R;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by qyhl on 2018/1/26.
 */

public class ItemCircleUserTxt implements ItemViewDelegate<CircleHomeBean> {
    private final List<CircleHomeBean> mDataList;
    private Context context;

    public ItemCircleUserTxt(Context context,List<CircleHomeBean> mDataList) {
        this.context = context;
        this.mDataList =mDataList;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.circle_item_circle_user;
    }

    @Override
    public boolean isForViewType(CircleHomeBean item, int position) {
        if (item.getType() == 1) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public void convert(ViewHolder holder, CircleHomeBean bean, int position) {
        //日期
        TextView date = holder.getView(R.id.date);
        if (position != 0) {
            //判断是否是同一天
            if (DateUtils.isSameDay(bean.getGmtCreate(), mDataList.get(position - 1).getGmtCreate())) {
                date.setVisibility(View.INVISIBLE);
            } else {
                date.setVisibility(View.VISIBLE);
                String time = DateUtils.circleUcenterTime(bean.getGmtCreate());
                SpanUtils spanUtils = new SpanUtils(context);
                if (time.contains("|")) {
                    spanUtils.append(time.substring(time.indexOf("|") + 1)).setBold().setFontSize(25, true)
                            .append(time.substring(0, time.indexOf("|"))).setBold().setFontSize(14, true);
                } else {
                    spanUtils.append(time).setFontSize(20, true).setBold();
                }
                date.setText(spanUtils.create());
            }
        } else {
            date.setVisibility(View.VISIBLE);
            String time = DateUtils.circleUcenterTime(bean.getGmtCreate());
            SpanUtils spanUtils = new SpanUtils(context);
            if (time.contains("|")) {
                spanUtils.append(time.substring(time.indexOf("|") + 1)).setBold().setFontSize(25, true)
                        .append(time.substring(0, time.indexOf("|"))).setBold().setFontSize(14, true);
            } else {
                spanUtils.append(time).setFontSize(20, true).setBold();
            }
            date.setText(spanUtils.create());
        }

        //封面图
        RelativeLayout coverLayout = holder.getView(R.id.cover_layout);
        coverLayout.setVisibility(View.GONE);

        //视频标志
        ImageView tag = holder.getView(R.id.video_tag);
        tag.setVisibility(View.GONE);

        //图片张数
        TextView picNum = holder.getView(R.id.picture_num);
        picNum.setVisibility(View.INVISIBLE);

        //描述
        TextView content = holder.getView(R.id.content);
        content.setText(bean.getContent());
        content.setBackgroundResource(R.drawable.circle_txt_bg);
        content.setPadding(10,15,4,10);



    }
}
